<?php
namespace ElementVip\Shop\Backend\Console;

use ElementVip\Shop\Backend\Model\City;
use Illuminate\Console\Command;

class ShopCityCommand extends Command
{

	protected $signature = 'shop-city:factory';

	protected $description = 'shop city factory.';

	/**
	 * Execute the console command.
	 */
	public function handle()
	{
		$data = $this->cityData();
		if (count($data) > 0) {
			foreach ($data as $item) {
				City::create($item);
			}
		}
	}

	private function cityData()
	{
		$data = config('city');

		foreach ($data as $key => $item) {
			if (City::where('name', $item['name'])->first()) {
				unset($data[$key]);
			}
		}

		return $data;
	}

}